#ifndef ASYNSOCKETCLIENT_H
#define ASYNSOCKETCLIENT_H



#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/asio/placeholders.hpp>
#include <boost/asio.hpp>
#include <boost/array.hpp>
#include <memory.h>

#include "utility.hpp"
#include "typetransfer.h"
#include "frame.h"
//#include "slaves/slavebase.h"

#include <string>
#include <iostream>
using boost::asio::ip::tcp;
using boost::asio::ip::address;
using namespace std;

class MainController;




class AsynSocketClient : public boost::enable_shared_from_this<AsynSocketClient> {
public:
    AsynSocketClient(MainController *main_controller,boost::asio::io_service &io_service, tcp::endpoint &endpoint);

    void Start();

    void AsyncWrite(const u_char *msg_data,const size_t len);
    void Write(const u_char *msg_data,const size_t len);
    void HandleDataCb(const u_char *msg_data,const size_t len);
private:
    void HandleConnect(const boost::system::error_code &error);
    void HandleWrite(const boost::system::error_code& error, size_t bytes_transferred);
    void HandleRead(const boost::system::error_code& error, size_t bytes_transferred);

private:
    boost::asio::io_service &io_service_;
    tcp::endpoint &endpoint_;
    tcp::socket socket_;

    Frame frame_;

    MainController *main_controller_;
};

typedef boost::shared_ptr<AsynSocketClient> AsynSocketClientPtr;

#endif // ASYNSOCKETCLIENT_H
